package edu.chinasoft.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import javax.servlet.annotation.WebServlet;
import org.apache.log4j.Logger;

import edu.chinasoft.pojo.User;
import edu.chinasoft.service.UserService;
import edu.chinasoft.service.UserServiceImp;

/**
 * 
 * @author cjogng
 * @date 2020年1月17日:上午11:55:44
 * @version V1.0
 * @Description: 生成更新用户页面
*/
@WebServlet(name="myUpdateUserPageForServlet",value="/servlet/updateuserpageforservlet")
public class  UpdateUserPageForServlet  extends HttpServlet {
	private static Logger logger = Logger.getLogger( UpdateUserPageForServlet .class);
	private UserService userService = new UserServiceImp();
	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" UpdateUserPageForServlet >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		//获取所要更新用户的id
		String idString = request.getParameter("id");
		int id = Integer.parseInt(idString);
		//封装到user对象里，调用服务器层方法获取用户的其他信息
		User user = new User();
		user.setId(id);
		User result = userService.findUserInfo(user);
		//把用户信息封装到html页面中，显示
		out.write("<!DOCTYPE html>     <html lang='en'>         <head>             <meta charset='utf-8'>         </head>         <body>         <form action='"+request.getContextPath()+"/servlet/updateuserforservlet' method='post'>         id：<input type='text' name='user_id' readonly='readonly' value='"+result.getId()+"'><br>");
		
		out.write("用户名：<input type='text' name='user_name' value='"+result.getUserName()+"'><br>");
		out.write("密码：<input type='password' name='user_password' value='"+result.getUserPassword()+"'><br>");
		out.write("备注：<input type='text' name='user_desc' value='"+result.getUserDesc()+"'><br>");
		
		if(result.getUserFlag().equals("1")) {
			out.write("状态：<input type='radio' name='user_flag' value='1' checked='checked'> 启用<input type='radio' name='user_flag' value='0'> 禁用");
		}else {
			out.write("状态：<input type='radio' name='user_flag' value='1' > 启用<input type='radio' name='user_flag' value='0'  checked='checked'> 禁用");
		}
		
		
		
		out.write("<br><input type='submit' value='更新'><input type='reset' value='清空'></form></body></html>");
		logger.debug(" UpdateUserPageForServlet >doGet end.......");
	}
	
	/**
	 * 
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" UpdateUserPageForServlet >doPost start.......");
		this.doGet(request, response);
		
		logger.debug(" UpdateUserPageForServlet >doPost end.......");
	}
	
}